<?php
/*
 * Hooligan - A sports facilities management software
 * Copyright (C) 2009/2010 Gianluca Bargelli <g.bargelli@gmail.com>,
 * Andrea Biocco <abiocco@gmail.com>
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 * Project home: <http://code.google.com/hooligan>
 *
*/
require_once('../Controller/Common/Controller_Common_Config.php');
require_once('../Template/Template_Admin.php');
/**
 * Description of Controller_Impianti_ModificaImpianto
 *
 * @author andrea
 */
class Controller_Gestore_ModificaGestore {

    public static function modGestore($user_gestore) {

        if (!array_key_exists('user_gestore', $_POST)) {
            $connection=new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
            $db = new Model_Db($connection);
            $sql="SELECT * FROM `Gestore` where Utente_username='".$user_gestore."'";
            $rs=$db->eseguiQuery($sql);
            $row = $rs->fetch_array(MYSQLI_ASSOC);
            $nascita_giorno=substr($row['data_n'], 8, 2);
            $nascita_mese=substr($row['data_n'], 5, 2);
            $nascita_anno=substr($row['data_n'], 0, 4);
            ?>

<form action="../http/modificaGestore.php" method="post">
    <table>
        <tr>
            <th colspan="2">Gestore:</th>
        </tr>
        <tr>
            <td>Username:</td>
            <td><input type="text" readonly name="user_gestore" value="<?php echo $row['Utente_username']; ?>"></td>
        </tr> 
        <tr>
            <td>Nome:</td>
            <td><input type="text" readonly name="nome" value="<?php echo $row['nome']; ?>"></td>
        </tr>
        <tr>
            <td>Cognome:</td>
            <td><input type="text" readonly name="cognome" value="<?php echo $row['cognome']; ?>"></td>
        </tr>
        <tr>
            <td>E-Mail:</td>
            <td><input type="text" name="email" value="<?php echo $row['email_cus']; ?>"></td>
        </tr>      
        <tr>
            <td>Data di nascita:</td>
            <td><input type="text" size="2" maxlength="2" name="nascita_giorno" value="<?php echo $nascita_giorno; ?>"> <input type="text" size="2" maxlength="2" name="nascita_mese" value="<?php echo $nascita_mese; ?>"> <input type="text" size="4" maxlength="4" name="nascita_anno" value="<?php echo $nascita_anno; ?>"></td>
        </tr>
        <tr>
            <td>Tel:</td>
            <td> <input type="text" name="tel" value="<?php echo $row['tel']; ?>"></td>
        </tr>
    </table>
    <input type="submit" value="Applica modifiche">
</form>
            <?php
        } else {
            //Tools_CustomDebug::niceDump($_GET);
            $connection=new mysqli(DB_HOST, DB_USER, DB_PASSWORD, DB_DATABASE);
            $db = new Model_Db($connection);
            $sql="update Gestore set email_cus='".$_POST['email']."', nome='".$_POST['nome']."', cognome='".$_POST['cognome']."', data_n='".$_POST['nascita_anno']."-".$_POST['nascita_mese']."-".$_POST['nascita_giorno']."', tel='".$_POST['tel']."' where Utente_username='".$_POST['user_gestore']."'";
            $rs=$db->eseguiQuery($sql);
            //manca la modifica per il cambio di amministratore che ha modificato l'impianto!
            header('location:adminUtente.php?filter=gestori');
        }
        ?>
<a href="../http/adminGestore.php">Indietro</a>
<?php
    }
}
?>
